package model;

import java.util.Scanner;

public class Arithmetic {
	private int[] a;
	
	public Arithmetic() {
		a = new int[10];
	}
	
	//gettor
	public int[] getA() {
		return a;
	}
	
	//settor
	public void setA(int[] arr) {
		this.a = arr;
	}
	
	//nhap mang
	public void enterDataA() {
		for(int i = 0; i < a.length; i++) {
			Scanner scanner = new Scanner(System.in);
			System.out.print("a[" + i +"] = ");
			a[i] = scanner.nextInt();
		}
		System.out.print("\n");
	}
	
	//xuat mang
	public void printDataA() {
		System.out.print("Mang a vua nhap: ");
		for(int i = 0; i < a.length; i++) {
			System.out.print(a[i] + "  ");
		}
		System.out.print("\n");
	}
	
	//tong mang
	public int totalDataA() {
		int total = 0;
		
		System.out.print("Tong mang: ");
		for(int i = 0; i < a.length; i++) {
			total += a[i];
		}
		
		return total;
	}
	
	//gia tri lon nhat trong mang
	public int maxValueDataA() {
		int max = a[0];
		System.out.print("Gia tri lon nhat: ");
		for(int i = 0; i < a.length; i++) {
			if(max < a[i]) {
				max = a[i];
			}
		}
		
		return max;
	}
	
	//sap xep mang theo chieu tang dan
	public void sortIncreaseDataA() {
		int temp = 0;
		for(int i = 0; i < a.length; i++) {
			for(int j = i + 1; j <a.length; j++) {
				if(a[i] > a[j]) {
					temp = a[i];
					a[i] = a[j];
					a[j] = temp;
				}
			}
		}
		
		System.out.print("Mang tang dan: ");
		for(int i = 0; i < a.length; i++) {
			System.out.print(a[i] + "  ");
		}
		
		System.out.print("\n");
	}
	
	public void sortDecreaseDataA() {
		int temp = 0;
		for(int i = 0; i < a.length; i++) {
			for(int j = i + 1; j < a.length; j++) {
				if(a[i] < a[j]) {
					temp = a[i];
					a[i] = a[j];
					a[j] = temp;
				}
			}
		}
		
		//xuat mang theo theo thu tu giam dan
		System.out.print("Mang giam: ");
		for(int i = 0; i < a.length; i++) {
			System.out.print(a[i] + "  ");
		}
		
		System.out.print("\n");
	}
	
	//kiem tra so nguyen to
	public boolean checkPrime(int n) {
		boolean isPrime = true;
		for(int i = 2; i < a.length; i++) {
			if(a[i] == 2) {
				isPrime = true;
			}
			else if(a[i] % i == 0) {
				return false;
			}
		}
		
		return isPrime;
	}
	
	//xuat so nguyen to
	public void printPrimeDataA() {
		System.out.print("So nguyen to: ");
		for(int i = 0; i < a.length; i++) {
			if(checkPrime(a[i]) == true) {
				System.out.print(a[i] + "  ");
			}
		}
		System.out.print("\n");
	}
	
	
}
